package com.xu.mb3.mbtools;

import org.apache.ibatis.type.TypeReference;

/**
 * 继承TypeReference的类, 可以调用getRawType()方法获取具体的泛型类型
 * 实现原理: 首先通过递归获取到父类TypeReference, 然后通过反射获取父类TypeReference的泛型参数
 *
 * @author xuguan
 * @since 2024/11/15
 */
public class TypeReferenceSample {

    public static class StrType extends TypeReference<String> {
    }

    public static class StrType2 extends StrType {
    }

    public static void typeReferenceSample() {
        final StrType strType = new StrType();
        final StrType2 strType2 = new StrType2();
        System.out.println("strType.getRawType() = " + strType.getRawType());
        System.out.println("strType2.getRawType() = " + strType2.getRawType());
    }

    public static void main(String[] args) {
        typeReferenceSample();
    }

}
